home *** CD-ROM | disk | FTP | other *** search
- unit ParentAnonymousPipeUnit;
-
- interface
-
- uses
- Classes, Windows;
-
- type
- TTestAnonymousPipe = class(TThread)
- private
- FUIString: String;
- FPipeHandle: Integer;
- //Two routines to simplify showing our progress
- procedure UpdateUI;
- procedure WriteString(const S: String);
- protected
- //Body of the thread
- procedure Execute; override;
- public
- constructor Create(PipeRead: Integer);
- end;
-
- implementation
-
- uses
- ParentMainFormUnit, SysUtils;
-
- constructor TTestAnonymousPipe.Create(PipeRead: Integer);
- begin
- inherited Create(False);
- FPipeHandle := PipeRead;
- end;
-
- procedure TTestAnonymousPipe.UpdateUI;
- begin
- with Form1.Memo1 do
- Text := Text + FUIString;
- end;
-
- procedure TTestAnonymousPipe.WriteString(const S: String);
- begin
- FUIString := S;
- Synchronize(UpdateUI);
- end;
-
- procedure TTestAnonymousPipe.Execute;
- const
- BytesToRead = 1000;
- var
- BytesRead: Integer;
- DataBuf: array[0..BytesToRead] of Char;
- begin
- repeat
- BytesRead := FileRead(FPipeHandle, DataBuf, BytesToRead);
- if BytesRead <> -1 then
- begin
- SetString(FUIString, DataBuf, BytesRead);
- Synchronize(UpdateUI);
- end
- until Terminated or (BytesRead = -1);
- if not Terminated then
- WriteString('Pipe is broken: ' + SysErrorMessage(GetLastError))
- end;
-
- end.
-